package editro.controller 
{
	import editro.events.system.AddNewTaskViewItemEvent;
	import editro.events.system.SystemEvent;
	import editro.events.view.DrawFloateLineEvent;
	import editro.model.ATECacheModel;
	import editro.view.components.AntTaskView;
	import editro.view.components.ArchorLinkLineOverlay;
	import editro.view.components.DockBar;
	import editro.view.components.TaskViewsContainer;
	import editro.view.components.ViewComponentsLayer;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import org.robotlegs.mvcs.Command;
	
	/**
	 * ...
	 * @author LEEF LEE_LEAF918@163.COM_QQ969442267
	 */
	public class StartupAppCommand extends Command 
	{
		[Inject] 
		public var model:ATECacheModel;
		
		override public function execute():void 
		{
			model.stageInstance = contextView.stage;
			//画线图层
			contextView.addChild(new TaskViewsContainer);
			//TASK元素层
			contextView.addChild(new ArchorLinkLineOverlay);
			//可视控制组件层
			contextView.addChild(new ViewComponentsLayer);
			contextView.addChild(new DockBar);
			//更新当前鼠标位置
			model.stageInstance.addEventListener(MouseEvent.MOUSE_MOVE, sendMoveEvent);
			model.stageInstance.addEventListener(MouseEvent.CLICK, clickOnBlinkAreaOnStage);
			//测试中，以下两行可以删除
			dispatch(new AddNewTaskViewItemEvent(AddNewTaskViewItemEvent.ADD_TASK_ITEM_TO_STAGE,new AntTaskView));
			dispatch(new AddNewTaskViewItemEvent(AddNewTaskViewItemEvent.ADD_TASK_ITEM_TO_STAGE,new AntTaskView));
			dispatch(new AddNewTaskViewItemEvent(AddNewTaskViewItemEvent.ADD_TASK_ITEM_TO_STAGE,new AntTaskView));
			dispatch(new AddNewTaskViewItemEvent(AddNewTaskViewItemEvent.ADD_TASK_ITEM_TO_STAGE,new AntTaskView));
			super.execute();
		}
		
		private function clickOnBlinkAreaOnStage(e:MouseEvent):void 
		{
			if (e.target == contextView.stage) {
				model.isOnFloatDrawingModel = false;
				dispatch(new DrawFloateLineEvent(DrawFloateLineEvent.CANCLE_FLOAT_DRAW, new Point(e.stageX, e.stageY)));
			}
		}
		
		private function sendMoveEvent(e:MouseEvent):void 
		{
			var p:Point = new Point(e.stageX, e.stageY);
			dispatch(new DrawFloateLineEvent(DrawFloateLineEvent.UPDATE_STAGE_CURSOR_POSITION, p));
			model.stageCursorPoint = p;
		}
	}

}